﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Super.Entities;
using Super.Infrastructure;

namespace Super.DomainService
{
    public class MoneyChangeTypeService : BaseService<MoneyChangeType>
    {

        private readonly DbContextAdapter _adp;
        private readonly BaseService<MoneyChangeType> _moneyChangeTypeService;
        public MoneyChangeTypeService(DbContextAdapter adp)
            : base(adp)
        {
            _adp = adp;
            _moneyChangeTypeService = new BaseService<MoneyChangeType>(_adp);
        }


        public MoneyChangeType GetStockChangeModel(string Name, MoneyChangeTypeEnum InOut)
        {
            var io = (int)InOut;
            var model = _moneyChangeTypeService.Repository.Find(a => a.Name.Contains(Name) && a.InOut == io).FirstOrDefault();
            if (model == null)
            {
                model = new MoneyChangeType();
                model.Name = Name;
                model.InOut = io;
                _moneyChangeTypeService.Repository.InsertOrUpdate(model);
                _adp.SaveChanges();
            }
            return model;
        }
    }
}
